import javax.swing.*;
import java.awt.*;
import java.util.Date;
import java.util.Timer;

public class Client extends JFrame {
    public static final int HEIGHT = 720;
    public static final int WIDTH = 1280;
    static GameBoard gameBoard = new GameBoard();
    static Game game = new Game();
    static int playerID = 0;

    public Client(String title) {
        super(title);

        setBounds((Toolkit.getDefaultToolkit().getScreenSize().width - WIDTH) / 2,
                (Toolkit.getDefaultToolkit().getScreenSize().height - HEIGHT) / 2,
                WIDTH, HEIGHT);
        setResizable(false);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        this.add(gameBoard);
        setVisible(true);
    }

    public static void main(String[] args) {
        JTextField host = new JTextField();
        int result = JOptionPane.showConfirmDialog(null, host,
                "Server Host", JOptionPane.OK_CANCEL_OPTION);
        if (result != JOptionPane.OK_OPTION) return;
        JTextField port = new JTextField();
        result = JOptionPane.showConfirmDialog(null, port,
                "Server Port", JOptionPane.OK_CANCEL_OPTION);
        if (result != JOptionPane.OK_OPTION) return;
        JTextField name = new JTextField();
        result = JOptionPane.showConfirmDialog(null, name,
                "Username", JOptionPane.OK_CANCEL_OPTION);
        if (result != JOptionPane.OK_OPTION) return;

        String clientName = name.getText();
        String serverHost = host.getText();
        String serverPort = port.getText();

        Daemon daemon = new Daemon(serverHost, serverPort);
        Daemon.joinGame(clientName);
        Daemon.updateStatus();

        java.util.Timer sync = new Timer(true);
        sync.schedule(daemon, new Date(), 20);

        new Client("Football Client - " + clientName);
    }
}
